<?php
class LZ_User
{
	var $id = 'user_id';
	var $name = 'name';
	var $nickname = 'nickname';
	var $password = 'password';
	var $email = 'email';
	var $status = 'status';
	
	var $table = 'user';
	
	function LZ_User()
	{
		$this->table = LZ_MYSQL_PREFIX.$this->table;
	}
	
	function add( $data = array())
	{
		global $db;
		$sql = make_insert_sql($this->table,$data);
		return ($db->query($sql));
	}
	
	function delete($user_id)
	{
		global $db;
		$sql = "DELETE FROM $this->table WHERE $this->id = '$user_id';";
		return $db->query($sql);
	}
	
	function update($user_id,$data)
	{
		global $db;
		$sql = make_update_sql($this->table,$data, array('user_id' => $user_id));
		return $db->query($sql);
	}
	function exists($username)
	{
		global $db;
		$sql = "SELECT * FROM `{$this->table}` WHERE `{$this->name}` = '$username' LIMIT 1";
		$r = $db->query($sql);
		return ($db->num_rows($r) > 0);
	}
	
	function check_password($name,$password)
	{
		global $db;
		$sql = "SELECT * FROM `{$this->table}` WHERE `{$this->name}` = '$name'  AND `{$this->password}` = '$password'  LIMIT 1";
		return $db->get_one($sql);
	}
	
	function get_one($user_id)
	{
		global $db;
		$sql = "SELECT * FROM `{$this->table}` WHERE `{$this->id}` = '$user_id';";
		return $db->get_one($sql);	
	}
	
	function get_list( $data = array() )
	{
		global $db;
		$sql = "SELECT * FROM $this->table ";
		return $db->get_all($sql);
	}
	
	function get_array()
	{
		$arr = $this->get_list();
		$re = array();
		foreach($arr as $user)
		{
			$re[$user[$this->id]] = $user['name'];
		}
		return $re;
	}
}
?>